<!--#include file="../Lib/base.asp"-->
<%

	dim datadb,datadb2
	dim i
	dim act:act=lcase(Cls.fget("act",0))
	select case act
		case "install":installdb
		case "editdb":editdb
		case "uninstall":uninstalldb
	end select
	
	sub installdb()
		dim p_Name:p_Name=cls.enhtml(cls.fget("p_Name",0))
		dim xml,t2
		set xml=server.createobject("microsoft.xmldom")
			xml.async=false
			xml.load(server.mappath("../plug/"&p_Name&"/config.xml"))
			datadb=Cls.db.dbload("1","p_num","[Plug]","","p_num desc")
			if ubound(datadb)>=0 then
				p_num=datadb(0,0)+1
			else
				p_num=1				
			end if
			p_Name=xml.documentelement.childnodes(0).text
			p_Title=xml.documentelement.childnodes(1).text
			p_Info=xml.documentelement.childnodes(2).text
			p_Type=xml.documentelement.childnodes(3).text
			p_Api=xml.documentelement.childnodes(4).text
			p_Admin_Url=xml.documentelement.childnodes(5).text
			p_Admin_Api=xml.documentelement.childnodes(6).text
			p_Author=xml.documentelement.childnodes(7).text
			p_Version=xml.documentelement.childnodes(8).text
			p_HomeWeb=xml.documentelement.childnodes(9).text
			InstallSql=xml.documentelement.childnodes(10).text
		set xml=nothing
		
		if cls.strlen(p_Name)<=0 then
			cls.echo "0参数错误"
			exit sub
		end if
		dim data:data=array(array("p_num",p_num,0,0),array("p_Name",p_Name,50,1),array("p_Title",p_Title,50,1),array("p_Info",p_Info,50,1),array("p_Type",p_Type,0,0),array("p_Api",p_Api,0,1),array("p_Admin_Url",p_Admin_Url,0,1),array("p_Admin_Api",p_Admin_Api,0,1),array("p_Author",p_Author,50,1),array("p_Version",p_Version,50,1),array("p_HomeWeb",p_HomeWeb,0,1),array("p_IsLock","开启",50,1))
		if cls.db.dbnew("Plug",data,"p_Name='"&p_Name&"'")=0 then
			cls.echo "0插件已存在，请勿重复安装"
			exit sub
			cls.die
		else
			get_sql p_Name,10
			cls.echo "1插件安装成功！"
			cls.die		
		end if
	end sub
		
	sub editdb()
		dim id:id=Cls.getint(Cls.fget("id",0),0)		
		dim p_num,p_Name,p_Title,p_Info,p_Type,p_Api,p_Admin_Url,p_Admin_Api,p_Author,p_Version,p_HomeWeb,p_IsLock
		
		p_num=Cls.getint(Cls.fpost("p_num",0),0)
		p_Title=Cls.enhtml(Cls.fpost("p_Title",0))
		p_Info=Cls.enhtml(Cls.fpost("p_Info",0))
		'p_Type=Cls.getint(Cls.fpost("p_Type",0),0)
		p_Api=Cls.enhtml(Cls.fpost("p_Api",0))
		p_Admin_Url=Cls.enhtml(Cls.fpost("p_Admin_Url",0))
		p_Admin_Api=Cls.enhtml(Cls.fpost("p_Admin_Api",0))
		p_Author=Cls.enhtml(Cls.fpost("p_Author",0))
		p_Version=Cls.enhtml(Cls.fpost("p_Version",0))
		p_HomeWeb=Cls.enhtml(Cls.fpost("p_HomeWeb",0))
		p_IsLock=Cls.enhtml(Cls.fpost("p_IsLock",0))
		
		Dim data
		data=array(array("p_num",p_num,0,0),array("p_Title",p_Title,50,1),array("p_Info",p_Info,50,1),array("p_Api",p_Api,0,1),array("p_Admin_Url",p_Admin_Url,0,1),array("p_Admin_Api",p_Admin_Api,0,1),array("p_Author",p_Author,50,1),array("p_Version",p_Version,50,1),array("p_HomeWeb",p_HomeWeb,0,1),array("p_IsLock",p_IsLock,50,1))
		if Cls.db.dbupdate("[Plug]","p_id="&id,data)=1 then
			Cls.echo "1"
		else
			Cls.echo "0数据出错"
		end if	
		Cls.die	
	end sub
		
	sub uninstalldb()
		dim p_Name:p_Name=cls.enhtml(cls.fget("p_Name",0))
		if cls.strlen(p_Name)>0 then
			Cls.db.dbdel "[Plug]","p_Name='"&p_Name&"'"
			get_sql p_Name,11
		end if
		Cls.echo "1"
		Cls.die
	end sub
	
	sub get_sql(byval t0,byval t1)
		dim xml,t2
		set xml=server.createobject("microsoft.xmldom")
			xml.async=false
			xml.load(server.mappath("../plug/"&t0&"/config.xml"))
			t2=xml.documentelement.childnodes(t1).text
		set xml=nothing
		if cls.strlen(t2)<=0 then
			exit sub
		end if
		dim i,arr
		arr=split(t2,"@@")
		for i=0 to ubound(arr)
			cls.db.exedb arr(i)
		next
	end sub
	
%>
<!--#include file="../lib/Sys_Top.asp"-->
<script>

function checkedit(the,id)
{
	var url,data;
	url="?act=editdb&id="+id+"";
	data="p_num="+encodeURIComponent($.trim(the.p_num.value));
	data+="&p_Title="+encodeURIComponent($.trim(the.p_Title.value));
	data+="&p_Info="+encodeURIComponent($.trim(the.p_Info.value));
	data+="&p_Type="+encodeURIComponent($.trim(the.p_Type.value));
	data+="&p_Api="+encodeURIComponent($.trim(the.p_Api.value));
	data+="&p_Admin_Url="+encodeURIComponent($.trim(the.p_Admin_Url.value));
	data+="&p_Admin_Api="+encodeURIComponent($.trim(the.p_Admin_Api.value));
	data+="&p_Author="+encodeURIComponent($.trim(the.p_Author.value));
	data+="&p_Version="+encodeURIComponent($.trim(the.p_Version.value));
	data+="&p_HomeWeb="+encodeURIComponent($.trim(the.p_HomeWeb.value));	
	data+="&p_IsLock="+encodeURIComponent($.trim(the.p_IsLock.value));	
	
	$.ajax({
	type:"post",
	cache:false,
	url:url,
	data:data,
	error:function(){$.message({type:"error",content:"服务器错误，操作失败！"});},
	success:function(_)
	{
		var act=_.substring(0,1);
		var info=_.substring(1);
		switch(act)
		{
			case "0":
				$.message({type:"error",content:info});
				break;
			case "1":
				$.message({type:"ok",content:"保存成功"});
				setTimeout("location.href='?'",1000);
				break;
			default:
				alert(_)
				break;
		}
	}
	});
	return false

}
$(function(){
	$(".install").click(
		function()
		{
			var p_Name=this.getAttribute('rel');
			var throughBox=$.dialog.through;
			throughBox({
				icon:'question',
				content:'确定要安装此插件吗？',
				lock:true,
				opacity:'0.5',
				ok:function(){
					var url,data;
					url='?act=install&p_Name='+p_Name;
					$.ajax({
					type:"get",
					cache:false,
					url:url,
					error:function(){$.message({type:"error",content:"服务器错误，操作失败！"});},
					success:function(_)
					{
						var act=_.substring(0,1);
						var info=_.substring(1);
						switch(act)
						{
							case "0":
								$.message({type:"error",content:info});
								break;
							case "1":
								$.message({type:"ok",content:info});
								setTimeout("location.href='?'",2500)
								break;
							default:
								alert(_);
								break;
						}
					}
					});
									
					},
				cancelVal:'\u53d6\u6d88',
				cancel:true 
			})
			//
		}
	)
	$(".uninstall").click(function(){
		var p_Name=this.getAttribute('rel');
		var throughBox=$.dialog.through;
			throughBox({
				icon:'question',
				content:'确定要卸载此插件？数据表会一同被删除！',
				lock:true,
				opacity:'0.5',
				ok:function(){
					var url='?act=uninstall&p_Name='+p_Name;
					$.ajax({
					type:"get",
					cache:false,
					url:url,
					error:function(){$.message({type:"error",content:"服务器错误，操作失败！"});},
					success:function(_)
					{
						if(_.substring(0,1)==0)
						{
							$.message({type:"error",content:_.substring(1)});
						}
						else
						{
							$.message({type:"ok",content:"卸载成功"});
								setTimeout("location.href='?'",2500)
						}
					}
					});
									
					},
				cancelVal:'取消',
				cancel:true 
			})
		
		})
	
 })
</script>
</head>
<body>
<div id="notice"><span>当前位置：</span>关键字 > <a href="?">关键字设置</a></div>
<%
	if act="edit" then	
	dim id:id=Cls.getint(Cls.fget("id",0),0)
	datadb=Cls.db.dbload("","p_num,p_Name,p_Title,p_Info,p_Type,p_Api,p_Admin_Url,p_Admin_Api,p_Version,p_Author,p_HomeWeb,p_IsLock","[Plug]","p_id="&id,"")
	%>
<div class="clear_fixed">
  <dl class="addlist">
    <form onSubmit="return checkedit(this,<%=id%>)">
      <dt><em>插件排序：</em>
        <input type="text" name="p_num" size="5" value="<%=datadb(0,0)%>"/>
        数字越小，排序越前</dt>
      <dt><em>插件名：</em>
        <input type="text" name="p_Name" size="50" value="<%=datadb(1,0)%>" disabled="disabled"/>
        英文，且为唯一标识，不可修改</dt>
      <dt><em>插件标题：</em>
        <input type="text" name="p_Title" size="50" value="<%=datadb(2,0)%>"/>
      </dt>
      <dt><em>插件类型：</em>
        <select name="p_Type" id="p_Type">
          <option value="1" <%if datadb(4,0)="1" then cls.echo"selected"%> >图文素材型插件</option>
          <option value="2" <%if datadb(4,0)="2" then cls.echo"selected"%> >远程调用型插件</option>
          <option value="3" <%if datadb(4,0)="3" then cls.echo"selected"%> >外部链接型插件</option>
          <option value="0" <%if datadb(4,0)="0" then cls.echo"selected"%> >系统功能型插件</option>
        </select>
        <br />
        【1图文素材型插件】，直接匹配关键字后，调用插件，有调用数据API。如图文素材，调用远程CMS，或者商城CMS<br />
        【2远程调用型插件】，左右匹配后，post粉丝留言到远程程序端进行处理并返回标准微信格式。如查天气、快递<br />
        【3外部链接型插件】，直接在图文素材里调用的插件链接，不返回任何数据。如微商城，微网站，大转盘，刮刮卡<br />
        【0系统功能型插件】，直接作为系统功能使用，如粉丝管理，菜单管理，会员管理，不与微信产生数据交互</dt>
      <dt><em>描述说明：</em>
        <textarea name="p_Info" cols="60" rows="5"><%=datadb(3,0)%></textarea>
      </dt>
      <dt><em>程序处理地址：</em>
        <input type="text" name="p_Api" size="50" value="<%=datadb(5,0)%>"/>
      </dt>
      <dt><em>后台配置入口：</em>
        <input type="text" name="p_Admin_Url" size="50" value="<%=datadb(6,0)%>"/>
      </dt>
      <dt><em>后台数据接口API：</em>
        <input type="text" name="p_Admin_Api" size="50" value="<%=datadb(7,0)%>"/>
      </dt>
      <dt><em>插件版本：</em>
        <input type="text" name="p_Version" size="20"/ value="<%=datadb(8,0)%>" disabled="disabled" />
      </dt>
      <dt><em>插件作者：</em>
        <input type="text" name="p_Author" size="20" value="<%=datadb(9,0)%>" disabled="disabled"/>
      </dt>
      <dt><em>作者官网：</em>
        <input type="text" name="p_HomeWeb" size="50" value="<%=datadb(10,0)%>" disabled="disabled"/>
      </dt>
      <dt><em>开启状态：</em>
        <select name="p_IsLock" id="p_IsLock">
          <option value="开启" <%if datadb(11,0)="开启" then cls.echo"selected"%>>开启</option>
          <option value="关闭" <%if datadb(11,0)="关闭" then cls.echo"selected"%>>关闭</option>
        </select>
      </dt>
      <dd>
        <input type="submit" name="send" value="保存" />
        <input type="button" value="返回" onClick="location.href='javascript:history.go(-1)'" />
      </dd>
    </form>
  </dl>
</div>
<%else%>
<div class="clear_fixed">
  <form>
    <table cellpadding="5" id="table">
      <tr>
        <th width="80">排序</th>
        <th width="150">插件名</th>
        <th width="120">插件类型</th>
        <th width="">插件描述</th>
        <th width="100">作者</th>
        <th width="80">版本</th>
        <th width="200">官网</th>
        <th width="80">开启状态</th>
        <th width="80">管理</th>
      </tr>
      <%datadb=Cls.db.dbload("","p_id,p_num,p_Title,p_Type,p_Info,p_Author,p_Version,p_HomeWeb,p_IsLock,p_Name","[Plug]","","p_num asc")
		if ubound(datadb)>=0 then
		for i=0 to ubound(datadb,2)%>
      <tr id="list_<%=datadb(0,i)%>">
        <td align="center" ><%=datadb(1,i)%></td>
        <td align="center" ><%=datadb(2,i)%></td>
        <td align="center" ><%if datadb(3,i)="0" then
		Cls.echo "【系统功能型插件】"
		elseif datadb(3,i)="1" then
		Cls.echo "【图文素材型插件】"
		elseif datadb(3,i)="2" then
		Cls.echo "【远程调用型插件】"
		elseif datadb(3,i)="3" then
		Cls.echo "【外部链接型插件】"
		end if
		%></td>
        <td align="center"><%=datadb(4,i)%></td>
        <td align="center"><%=datadb(5,i)%></td>
        <td align="center"><%=datadb(6,i)%></td>
        <td align="center"><a href="<%=datadb(7,i)%>" target="_blank"><%=datadb(7,i)%></a></td>
        <td align="center" ><span <%if datadb(8,i)="关闭" then%>style="color:#f00"<%end if%>><%=datadb(8,i)%></span></td>
        <td align="center" ><a href="?act=edit&id=<%=datadb(0,i)%>">编辑</a>　<a href="javascript:;" class="uninstall" rel="<%=datadb(9,i)%>">卸载</a></td>
      </tr>
      <%next
	  end if
	  	
		'加载插件目录的全部插件
	  	dim fso,fsofolder,fsocontent,fsocount,xml
		set fso=createobject("scripting.filesystemobject")
		set fsofolder=fso.getfolder(server.mappath("../plug/"))
		set fsocontent=fsofolder.files
		for each fsocount in fsofolder.subfolders
		if cls.isfile("../plug/"&fsocount.name&"/config.xml") then
		
		'查询Plug数据库，是否已经安装插件
		datadb=Cls.db.dbload("","p_num,p_Name,p_Title,p_Info,p_Type,p_IsLock,p_Author,p_Version,p_HomeWeb","[Plug]","p_Name='"&fsocount.name&"'","")
		if ubound(datadb)<0 then
			set xml=server.createobject("microsoft.xmldom")
			xml.async=false
			xml.load(server.mappath("../plug/"&fsocount.name&"/config.xml"))
			p_num=0
			p_Name=xml.documentelement.childnodes(0).text
			p_Title=xml.documentelement.childnodes(1).text
			p_Info=xml.documentelement.childnodes(2).text
			p_Type=xml.documentelement.childnodes(3).text
			p_IsLock="关闭"
			p_Author=xml.documentelement.childnodes(7).text
			p_Version=xml.documentelement.childnodes(8).text
			p_HomeWeb=xml.documentelement.childnodes(9).text
			isInstall=0
		%>
        <tr>
          <td align="center" ><%=p_num%></td>
          <td align="center" ><%=p_Title%></td>
          <td align="center" >
		<%if p_Type="0" then
		Cls.echo "【系统功能型插件】"
		elseif p_Type="1" then
		Cls.echo "【图文素材型插件】"
		elseif p_Type="2" then
		Cls.echo "【远程调用型插件】"
		elseif p_Type="3" then
		Cls.echo "【外部链接型插件】"
		end if
		%></td>
          <td align="center"><%=p_Info%></td>
          <td align="center"><%=p_Author%></td>
          <td align="center"><%=p_Version%></td>
          <td align="center"><a href="<%=p_HomeWeb%>" target="_blank"><%=p_HomeWeb%></a></td>
          <td align="center" style="color:#00F"><%=p_IsLock%></td>
          <td align="center"><a href="javascript:;" rel="<%=fsocount.name%>" class="install" style="color:#F00;">安装</a></td>
        </tr>
        <%	end if
		end if%>
        <%next%>
        <%set xml=nothing%>
        <%set fsofolder=nothing%>
        <%set fsocontent=nothing%>
      </tbody>
    </table>
  </form>
</div>
<%end if%>
</body>
</html>
